package gttp.nspa.client.adm.activity;

import gttp.nspa.client.adm.place.BillingListPlace;
import gttp.nspa.client.adm.rpc.IBillingServiceAsync;
import gttp.nspa.shared.om.Billing;
import gttp.nspa.shared.om.Billing.Status;
import gttp.nspa.shared.utils.DateExUtils;

import java.util.Date;
import java.util.List;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;

public class BillingListActivity extends AbstractActivity implements IBillingList.Presenter {

    @Inject
    private IBillingList         ui;

    @Inject
    private PlaceController      placec;

    @Inject
    private IBillingServiceAsync service;

    public void start(AcceptsOneWidget panel, EventBus eventBus) {
        panel.setWidget(ui);
    }

    public void onListBillRequest(Long from, Long to, Status billStatus, AsyncCallback<List<Billing>> cb) {
        if (from == null) {
            from = DateExUtils.getStartOfDay(new Date()).getTime();
        }

        if (to == null) {
            to = DateExUtils.getEndOfDay(new Date()).getTime();
        }

        service.listBy(from, to, null, null, null, null, null, billStatus, 0, 0, null, cb);
    }

    public void onAddingNewBill() {
    }

    public void onPayingBill(long billId) {
    }

    public void onSelectingLocker(long billId, String lockerCode) {
    }

    public void onSelectingCustomer(long billId, String customerAlias) {
    }

    public void onViewingOrders(long billId) {
    }

    public void withPlace(BillingListPlace place) {
        if (place.reload) {
            ui.reload(place.from, place.to, place.status);
        }
    }
}
